#!/bin/bash

if [[ $# -ne 4 ]];
then
  echo "缺失必须的参数"
  exit 0
fi

v_host=$1
v_port=$2

d_host=$3
d_port=$4

echo -e "转发配置：$v_host:$v_port ---> $d_host:$d_port"

# 配置前
iptables -L -t nat

# 正向代理
iptables -t nat -A PREROUTING --dst "$v_host" -p tcp --dport "$v_port" -j DNAT --to-destination "$d_host:$d_port"
# 反向代理
iptables -t nat -A POSTROUTING --dst "$d_host" -p tcp --dport "$d_port" -j SNAT --to-source "$v_host"

# 配置后
iptables -L -t nat

